from urllib import request

from flask import Flask, render_template, session, redirect, url_for

app = Flask(__name__)


@app.route('/')
def index():
    msg = " \n my name is baimeidashu.com , China up!"
    return render_template("index.html", data=msg)


@app.route('/news')  # 增加一个news页面
def newspage():
    newsContent = "全国上下一心支持武汉，武汉加油！"
    return render_template("news.html", data=newsContent)



@app.route('/product/',methods=['GET'])# 增加一个product页面
def productpage():
    a = "悟空显卡"
    return render_template("product.html",data=a)


@app.route('/login')
def loginpage():
    return render_template("login.html")

@app.route('/loginProcess',methods=['POST','GET'])
def loginProcesspage():
    if request.method=='POST':
        nm=request.form['nm']
        pwd=request.form['pwd']
        if nm=='cao' and pwd=='123':
            session['username']=nm             #使用session存储方式，session默认为数组，给定key和value即可
            return redirect(url_for('index'))  #重定向跳转到首页
        else:
            return 'the username or userpwd does not match!'

if __name__ == "__main__":
    # app.run(port=2020, host="127.0.0.1", debug=True)
    app.run(port=2020, host="0.0.0.0")